﻿using System;
using System.Threading.Tasks;
using AutoMapper;
using GMS.IServices;
using GMS.Models.Dto;
using Microsoft.AspNetCore.Mvc;

namespace GMS.API.Controllers
{
    [ApiController]
    [Route("UserRoles")]
    public class UserRolesController : ControllerBase
    {
        private readonly IMapper _mapper;
        private readonly IUserRolesService _userRolesService;

        public UserRolesController(IMapper mapper, IUserRolesService userRolesService)
        {
            _mapper = mapper;
            _userRolesService = userRolesService;
        }

        [HttpPost]
        public async Task<IActionResult> Added(UserRolesDto dto)
        {
            var res = await _userRolesService.AddedAsync(dto);
            return res > 0
                ? StatusCode(200, new { code = 200, message = "用户添加角色成功" })
                : BadRequest(new { code = 500, message = "用户添加角色失败" });
        }

    }
}